import { constantRoutes, asyncRoutes } from '@/router'
export default {
  namespaced: true,
  state: {
    routes: []
  },
  mutations: {
    setRouter(state, payload) {
      state.routes = [...constantRoutes, ...payload]
    }
  },
  actions: {
    filterRoutes(context, payload) {
      let myRouter = asyncRoutes.filter(item => payload.menus.indexOf(item.name) > -1)
      myRouter = [...myRouter, { path: '*', redirect: '/404', hidden: true }]
      context.commit('setRouter', myRouter)
      return myRouter
    }
  }
}
